import datetime
from .models import *
from .serializers import *
from rest_framework import mixins
from rest_framework import viewsets
from rest_framework.filters import SearchFilter, OrderingFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.response import Response
from common.custommixins import CustomListModelMixin, CustomRetrieveModelMixin
from common.custommodelviewset import CustomModelViewSet
from .myfilter import *
from .serializers import *
from .mypage import *
from rest_framework import permissions

class VideoView(CustomModelViewSet):
    queryset = Video_web1.objects.all()
    serializer_class = VideosModelSerializer
    pagination_class=MyPage
    permission_classes = [permissions.IsAdminUser]
    filter_backends = (DjangoFilterBackend,SearchFilter,OrderingFilter)
    filterset_class=VideosFilter
    #搜索
    search_fields=('name')
    ordering_fields=('id')

    def retrieve(self,request,*args, **kwargs):
        instance=self.get_object()
        instance.click_num+=1
        instance.save()
        serializer=self.get_serializer(instance)
        return Response(serializer.data)
class VideosCategoryModelSerializer(CustomModelViewSet):
    queryset = VideosCategory.objects.all()
    serializer_class = VideosCategoryModelSerializer
    pagination_class=MyPage
    permission_classes = [permissions.IsAdminUser]
    filter_backends = (DjangoFilterBackend,SearchFilter,OrderingFilter)
    filterset_class=VideosCategoryFilter
    #搜索
    search_fields=('name')
    ordering_fields=('parent','id')

    def retrieve(self,request,*args, **kwargs):
        instance=self.get_object()
        instance.click_num+=1
        instance.save()
        serializer=self.get_serializer(instance)
        return Response(serializer.data)
